package xyz.renyumeng.xkm.es.controller;

import org.springframework.web.bind.annotation.*;
import xyz.renyumeng.xkm.dto.base.SearchPage;
import xyz.renyumeng.xkm.es.service.EsShopService;
import xyz.renyumeng.xkm.model.es.EsProduct;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author renyumeng
 * @date Created in 20:14 2023/7/3
 */

@RestController
@RequestMapping("/admin/es/shop/inner")
public class ShopController {

    @Resource
    private EsShopService esShopService;


    @GetMapping("/{page}/{size}")
    public SearchPage<List<EsProduct>> pageWithFilter(@PathVariable Integer page,
                                                      @PathVariable Integer size,
                                                      @RequestParam(value = "filter", required = false) String filter) {
        return esShopService.searchProduct(filter, page, size);
    }

    @GetMapping("/owner/{page}/{size}/{ownerId}")
    public SearchPage<List<EsProduct>> pageByOwnerId(
            @PathVariable Integer page,
            @PathVariable Integer size,
            @PathVariable Long ownerId
    ) {
        return esShopService.pageByOwnerId(page,size,ownerId);
    }

    @GetMapping("/isListed/{productId}/{isListed}")
    public Boolean getEsProductIdWithIsListed(@PathVariable Long productId,@PathVariable Integer isListed){
        return esShopService.getEsProductIdWithIsListed(productId,isListed);
    }

    @PutMapping
    public EsProduct save(@RequestBody EsProduct esProduct) {
        return esShopService.save(esProduct);
    }

    @GetMapping("/{productId}")
    public EsProduct getEsProductById(@PathVariable Long productId) {
        return esShopService.getEsProductById(productId);
    }

    @GetMapping("/owner/isSole/{page}/{size}/{ownerId}")
    public SearchPage<List<EsProduct>> pageByOwnerIdIsSole(
            @PathVariable Integer page,
            @PathVariable Integer size,
            @PathVariable Long ownerId,
            @RequestParam(value = "isSole") Integer isSole
    ) {
        return esShopService.pageByOwnerIdIsSole(page,size,ownerId,isSole);
    }

}
